package yao.guava.str;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import com.google.common.base.CharMatcher;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;



/**
 * 字符串处理
 * @author chenyao
 *
 */
public class StrTest {
	
	/**
	 * 字符串拼接
	 */
	@Test
	public void testJoiner() {
		Joiner joiner = Joiner.on(",").skipNulls();
		String string = joiner.join("zhang", null, "1");
		assertEquals("equal1111", "zhang,1", string);
		//查看src学到的东西
		//1.实例不可变，保证线程安全		
	}
	
	//拆分器[Splitter]
	@Test
	public void testSplitter() {
		Iterable<String> split = Splitter.on(",").trimResults().omitEmptyStrings().split("foo,bar,,   qux");
		System.out.println(split);
	}
	
	//字符匹配器[CharMatcher]
    //怎么才算匹配字符？
    //如何处理这些匹配字符？
	@Test
	public void testCharMatcher() {
		String string = "11111113fsdf";
		String noControl = CharMatcher.JAVA_ISO_CONTROL.removeFrom(string); //移除control字符
		String theDigits = CharMatcher.DIGIT.retainFrom(string); //只保留数字字符
		System.out.println(theDigits);
		String spaced = CharMatcher.WHITESPACE.trimAndCollapseFrom(string, ' ');//去除两端的空格，并把中间的连续空格替换成单个空格
		String noDigits = CharMatcher.JAVA_DIGIT.replaceFrom(string, "*"); //用*号替换所有数字
		String lowerAndDigit = CharMatcher.JAVA_DIGIT.or(CharMatcher.JAVA_LOWER_CASE).retainFrom(string);
		// 只保留数字和小写字母
	}
	
	/**
	 * 
	 */
	@Test
	public void testCharsets() {
		
	}
	
	//CaseFormat
	public void testCaseFormat() {
	
	}
	

}
